package com.hxc.interest.service.impl;

import java.util.List;

import com.hxc.common.core.domain.AjaxResult;
import com.hxc.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hxc.interest.mapper.TSummaryInfoMapper;
import com.hxc.interest.domain.TSummaryInfo;
import com.hxc.interest.service.ITSummaryInfoService;

/**
 * 乡村简介Service业务层处理
 * 
 * @author hxc
 * @date 2021-08-20
 */
@Service
public class TSummaryInfoServiceImpl implements ITSummaryInfoService 
{
    @Autowired
    private TSummaryInfoMapper tSummaryInfoMapper;

    /**
     * 查询乡村简介
     * 
     * @param id 乡村简介主键
     * @return 乡村简介
     */
    @Override
    public TSummaryInfo selectTSummaryInfoById(Long id)
    {
        TSummaryInfo summaryInfo = tSummaryInfoMapper.selectTSummaryInfoById(id);
        if(ObjectUtils.isNotEmpty(summaryInfo)){
            if(StringUtils.isNotBlank(summaryInfo.getBannerImg())){
                summaryInfo.setImgList(summaryInfo.getBannerImg().split(","));
            }
        }
        return summaryInfo;
    }

    /**
     * 查询乡村简介列表
     * 
     * @param tSummaryInfo 乡村简介
     * @return 乡村简介
     */
    @Override
    public List<TSummaryInfo> selectTSummaryInfoList(TSummaryInfo tSummaryInfo)
    {
        List<TSummaryInfo> summaryInfoList = tSummaryInfoMapper.selectTSummaryInfoList(tSummaryInfo);
        if(summaryInfoList.size() > 0){
            summaryInfoList.forEach(summaryInfo ->{
                if(StringUtils.isNotBlank(summaryInfo.getBannerImg())){
                    summaryInfo.setImgList(summaryInfo.getBannerImg().split(","));
                }
            });
        }
        return summaryInfoList;
    }

    /**
     * 新增乡村简介
     * 
     * @param tSummaryInfo 乡村简介
     * @return 结果
     */
    @Override
    public int insertTSummaryInfo(TSummaryInfo tSummaryInfo)
    {
        tSummaryInfo.setCreateTime(DateUtils.getNowDate());
        return tSummaryInfoMapper.insertTSummaryInfo(tSummaryInfo);
    }

    /**
     * 修改乡村简介
     * 
     * @param tSummaryInfo 乡村简介
     * @return 结果
     */
    @Override
    public int updateTSummaryInfo(TSummaryInfo tSummaryInfo)
    {
        return tSummaryInfoMapper.updateTSummaryInfo(tSummaryInfo);
    }

    /**
     * 批量删除乡村简介
     * 
     * @param ids 需要删除的乡村简介主键
     * @return 结果
     */
    @Override
    public int deleteTSummaryInfoByIds(Long[] ids)
    {
        return tSummaryInfoMapper.deleteTSummaryInfoByIds(ids);
    }

    /**
     * 删除乡村简介信息
     * 
     * @param id 乡村简介主键
     * @return 结果
     */
    @Override
    public int deleteTSummaryInfoById(Long id)
    {
        return tSummaryInfoMapper.deleteTSummaryInfoById(id);
    }

    /**
     * 功能描述: 根据类型查询最新的一条数据
     * @author yzj
     */
    @Override
    public AjaxResult querySummaryByType(Integer summaryType) {
        TSummaryInfo summaryInfo = tSummaryInfoMapper.querySummaryByType(summaryType);
        if(ObjectUtils.isNotEmpty(summaryInfo)){
            if(StringUtils.isNotBlank(summaryInfo.getBannerImg())){
                summaryInfo.setImgList(summaryInfo.getBannerImg().split(","));
            }
        }
        return AjaxResult.success("success", summaryInfo);
    }

}
